package ApplicationStart.Domain;

import lombok.Data;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Collection;
import java.util.Collections;


@Data
@Entity
public class ReaderBean implements UserDetails{

    @Id
    private String id;
    @Column
    private String userName;
    @Column
    private String password;
    @Column
    private boolean isNonLock; //Account 冻结
    @Column
    private boolean isAccountNonExpired;//账号是否过期
    @Column
    private boolean isCredentialNonExpired; //认证是否过期
    @Column
    private boolean isEnable; //是否能被使用


    /**
     * 权限设置
     * @return 返回权限集合
     */
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return Collections.singletonList(new SimpleGrantedAuthority("READER")); //默认都是有这个权限
    }

    @Override
    public String getPassword() {
        return this.password;
    }

    @Override
    public String getUsername() {
        return this.userName;
    }

    @Override
    public boolean isAccountNonExpired() {
        return this.isAccountNonExpired;
    }

    @Override
    public boolean isAccountNonLocked() {
        return this.isNonLock;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return this.isCredentialNonExpired;
    }

    @Override
    public boolean isEnabled() {
        return this.isEnable;
    }
}
